package com.nuanshui.heatedloan.service.services;

import com.alibaba.dubbo.config.annotation.Reference;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserService;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserServiceConstant;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserServiceFactory;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserServiceNameConverter;
import org.springframework.stereotype.Service;

/**
 * Created by zxh on 2017/2/10.
 */
@Service
public class ThirdUserServiceFactoryProxy implements ThirdUserServiceFactory {

    @Reference(group = ThirdUserServiceConstant.QQUserService,url= GlobalParam.USER_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.USER_DUBBO_SERVER_VERSION)
    private ThirdUserService qqUserService;

    @Reference(group = ThirdUserServiceConstant.WeiboUserService,url= GlobalParam.USER_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.USER_DUBBO_SERVER_VERSION)
    private ThirdUserService weiboUserService;

    @Reference(group = ThirdUserServiceConstant.WeixinUserService,url= GlobalParam.USER_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.USER_DUBBO_SERVER_VERSION)
    private ThirdUserService weixinUserService;

    public ThirdUserServiceFactoryProxy()
    {

    }

    private ThirdUserServiceNameConverter converter=new ThirdUserServiceNameConverter();

    @Override
    public ThirdUserService GetThirdUserService(int accountType)
    {
        String serviceName=converter.convert(accountType);

        return GetThirdUserService(serviceName);
    }

    @Override
    public ThirdUserService GetThirdUserService(String name)
    {
        if(name.equals(ThirdUserServiceConstant.QQUserService))
        {
            return qqUserService;
        }
        else if(name.equals(ThirdUserServiceConstant.WeixinUserService))
        {
            return weixinUserService;
        }
        else if(name.equals(ThirdUserServiceConstant.WeiboUserService))
        {
            return weiboUserService;
        }

        return null;
    }
}
